package com.voicechat.firstmet.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.activity.BuyVIPActivity;
import com.voicechat.firstmet.activity.IMChatActivity;
import com.voicechat.firstmet.adapter.FristVIPBannerAdapter;
import com.voicechat.firstmet.base.BaseFragment;
import com.voicechat.firstmet.bean.FristMetBean;
import com.voicechat.firstmet.bean.MySelfInfoBean;
import com.voicechat.firstmet.bean.VipCustomBean;
import com.voicechat.firstmet.client.OssClient;
import com.voicechat.firstmet.client.OssConfig;
import com.voicechat.firstmet.imcontrol.MediaUtil;
import com.voicechat.firstmet.net.HTTPAPI;
import com.voicechat.firstmet.net.service.FristMetService;
import com.voicechat.firstmet.net.service.MeInfoService;
import com.voicechat.firstmet.utils.ConstantSet;
import com.voicechat.firstmet.utils.ParcelableUtils;
import com.voicechat.firstmet.utils.PhoneUtils;
import com.voicechat.firstmet.utils.PopUtils;
import com.voicechat.firstmet.utils.SPUtils;
import com.voicechat.firstmet.utils.ThreadManager;
import com.voicechat.firstmet.utils.Utils;
import com.voicechat.firstmet.view.RadarView2;
import com.voicechat.firstmet.view.recyclerview.mo.MoCardAdapter;
import com.voicechat.firstmet.view.recyclerview.mo.MoCardCallback;
import com.voicechat.firstmet.view.recyclerview.mo.MoCardLayoutManager;
import com.voicechat.firstmet.view.recyclerview.mo.MoRecyclerView;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import library.banner.layoutmanager.BannerLayout;

import static android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE;


/**
 * 附件的人
 * Created by Administrator on 2018/8/28.
 */

public class NearbyFragment extends BaseFragment {

    @BindView(R.id.recycleview_firstmet)
    MoRecyclerView recycleviewFirstmet;
    @BindView(R.id.image_unlike)
    ImageView imageUnlike;
    @BindView(R.id.image_like)
    ImageView imageLike;
    @BindView(R.id.radar_view)
    RadarView2 radarView;
    @BindView(R.id.default_image_view)
    ImageView defaultImageView;
    @BindView(R.id.linear_layout)
    LinearLayout linearLayout;
    private MoCardLayoutManager manager;
    private ArrayList<FristMetBean.PageBean.ListBean> list;
    private MoCardAdapter moCardAdapter;
    private MoCardCallback callback;
    private ItemTouchHelper helper;
    private String TAG = "NearbyFragment";
    private int page;
    private String token;
    private String deviceInfo;
    private Runnable runnable;

    private String userId;
    private String voiceName;//语音文件
    public String[] stringsText;
    public String[] stringsTitle;
    private int count;//滑动的次数
    MySelfInfoBean.ObjectBean mySeleInfo;
    //播放音频
    private MediaUtil mediaUtil;
    private ImageView imagePlay;
    @Override
    protected int loadLayout() {
        return R.layout.fragment_nearby;
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        ButterKnife.bind(this, view);
        initView();
        //radarView.start();
        setFristMetList();
        radarView.setVisibility(View.VISIBLE);
        radarView.start();
    }
    /**
     * @return
     * @method
     * @description 数据控件实例化
     * @date: 2018/11/14 19:41
     * @author: ljp
     */
    private void initView() {
        stringsText = getResources().getStringArray(R.array.vip_text);
        stringsTitle = getResources().getStringArray(R.array.vip_title);
        for (int i = 0; i < stringsBag.length; i++) {
            vipCustomBeans.add(new VipCustomBean(stringsBag[i], stringsIcon[i], stringsText[i], stringsTitle[i]));
        }
        page = 1;
        token = SPUtils.getEditoString(SPUtils.SP_TOKEN);
        deviceInfo = PhoneUtils.getDeviceInfo(context);
        mySeleInfo = MySelfInfoBean.ObjectBean.CREATOR.createFromParcel(ParcelableUtils.unmarshall(
                SPUtils.getEditoString(SPUtils.SP_MYSELFINFO)));
        userId = mySeleInfo.getId();
        list = new ArrayList<>();
        manager = new MoCardLayoutManager(context);
        recycleviewFirstmet.setLayoutManager(manager);//布局管理器
        moCardAdapter = new MoCardAdapter(context, list);
        //moCardAdapter.setHasStableIds(true);
        recycleviewFirstmet.setAdapter(moCardAdapter);//适配器
        callback = new MoCardCallback(recycleviewFirstmet, context);
        //callback = new MoCardCallback(recycleviewFirstmet,moCardAdapter,list);
        helper = new ItemTouchHelper(callback);
        helper.attachToRecyclerView(recycleviewFirstmet);//关联
        recycleviewFirstmet.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                RecyclerView.Adapter adapter = recyclerView.getAdapter();
                //adapter.
                if (newState == SCROLL_STATE_IDLE) {
                }
                int itemCount = layoutManager.getItemCount();
                // Log.i(TAG, "onScrollStateChanged: ---------"+itemCount);
                super.onScrollStateChanged(recyclerView, newState);
            }
            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                int layoutDirection = layoutManager.getItemCount();
                if (layoutDirection == 0) {
                    page++;
                    setFristMetList();
                    radarView.setVisibility(View.VISIBLE);
                    radarView.start();
                }
            }
        });
        callback.setSwipeListener(new MoCardCallback.OnSwipeListener() {
            @Override
            public void onSwiped(int adapterPosition, int direction) {//切换卡片后
                if (direction == ItemTouchHelper.DOWN || direction == ItemTouchHelper.UP) {
                    return;
                }
                switch (direction) {
                    case ItemTouchHelper.LEFT://左滑不喜欢
                        // toast_MakeText("不喜欢");
                        if (adapterPosition != list.size()) {
                            setUnLike(adapterPosition, 1, list.get(adapterPosition));
                        }
                        break;
                    case ItemTouchHelper.RIGHT://右滑喜欢
                        //toast_MakeText("喜欢");
                        if (adapterPosition != list.size()) {
                            setLike(adapterPosition, 1, list.get(adapterPosition));
                        }
                        break;
                }
                if (mediaUtil != null) {
                    mediaUtil.stop();
                }
                //list.remove(adapterPosition);
            }

            @Override
            public void onSwipeTo(RecyclerView.ViewHolder viewHolder, float offXset, float offYset) {//获取滑动值
                if (offXset < -100) {//左滑
                    imageLike.setVisibility(View.GONE);
                    imageUnlike.setVisibility(View.VISIBLE);
                    // Log.i(TAG, "onSwipeTo: ----imageUnlike----");

                } else if (offXset > 100) {//右滑
                    imageLike.setVisibility(View.VISIBLE);
                    imageUnlike.setVisibility(View.GONE);
                    // Log.i(TAG, "onSwipeTo: ----imageLike----");
                } else {
                    imageLike.setVisibility(View.GONE);
                    imageUnlike.setVisibility(View.GONE);
                }
            }
        });
        moCardAdapter.setItemClick(new MoCardAdapter.ItemClick() {
            @Override
            public void setItemClickPosition(View view, int position) {
                switch (view.getId()) {
                    case R.id.image_play://播放语音介绍按钮
                        imagePlay = ((ImageView) view);
                        if (!TextUtils.isEmpty(list.get(position).getVoiceInfo())) {
                            String voiceName = ConstantSet.VOICEINTR + ConstantSet.VOICEINTR_PATH + Utils.getVoiceName(list.get(position).getVoiceInfo());
                            try {
                                player(voiceName, view);
                            } catch (FileNotFoundException e) {
                                e.printStackTrace();
                            }
                        }
                        break;
                    case R.id.image_unlike://不喜欢
                        callback.toLeft(recycleviewFirstmet);
                        //setUnLike(position);
                        //setUnLike(position,2,list.get(position));
                        break;
                    case R.id.image_call://搭讪
                        // sendGift();
                        //sendGiftAccost(list.get(position));
                        FristMetBean.PageBean.ListBean listBean = list.get(position);
                        IMChatActivity.navToChat(context, listBean.getUserId(), listBean.getNickName(), String.valueOf(listBean.getType()), "accost");
                        break;
                    case R.id.image_like://喜欢
                        callback.toRight(recycleviewFirstmet);
                        //setLike(position,2,list.get(position));
                        break;
                }
            }
        });
        defaultImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                defaultImageView.setEnabled(false);
                page = 1;
                setFristMetList();
            }
        });
    }

    /**
     * @param listBean
     * @return
     * @method
     * @description 搭讪送礼物
     * @date: 2018/12/1 10:43
     * @author: ljp
     */
    private void sendGiftAccost(FristMetBean.PageBean.ListBean listBean) {
        MeInfoService.sendGiftChat(mySeleInfo.getId(), token, deviceInfo, listBean.getUserId(), "", "", "6", "1").subscribe(result -> {
            Log.i(TAG, "onReceive: ---------" + result);
            if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETRUN_SUCCESS) {
                toast_MakeText("搭讪成功！");
                IMChatActivity.navToChat(context, listBean.getUserId(), listBean.getNickName(), String.valueOf(listBean.getType()), "accost");
            }
            if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETURN_NO_TOKEN) {
                Utils.setToken(context);
            } else {
                toast_MakeText(result.getMsg());
            }
        }, throwable -> {
            Log.i(TAG, "onReceive: ----" + throwable.toString());
        });

    }

    /**
     * @return
     * @method
     * @description 初见网络请求
     * @date: 2018/11/14 14:58
     * @author: ljp
     */
    private void setFristMetList() {
        recycleviewFirstmet.setVisibility(View.GONE);
        String longitude;
        String dimension = "";
        String longitudeUpper = "";
        String dimensionLower = "";
        if (TextUtils.isEmpty(SPUtils.getEditoString("dimensionUpper"))) {
            longitude = SPUtils.getEditoString("longitude");
            dimension = SPUtils.getEditoString("dimension");
            dimensionLower = SPUtils.getEditoString("dimension");
            longitudeUpper = SPUtils.getEditoString("longitude");
        } else {
            longitude = SPUtils.getEditoString("longitude");
            dimension = SPUtils.getEditoString("dimension");
            dimensionLower = SPUtils.getEditoString("dimensionUpper");
            longitudeUpper = SPUtils.getEditoString("longitudeUpper");
        }
        //Log.i(TAG, "setFristMetList: --longitude-----" + longitude + "--dimension--" + dimension);
        FristMetService.fristMetList(userId, token, deviceInfo, page + "",
                longitude, dimension, longitudeUpper, dimensionLower).subscribe(fristMetBean -> {
            //Log.i(TAG, "setFristMetList: --------" + fristMetBean.toString());
            if (fristMetBean.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETRUN_SUCCESS) {
                count = fristMetBean.getObject().getCount();
                // Log.i(TAG, "setFristMetList: -----------"+fristMetBean.getMap().toString());
                int i = fristMetBean.getPage().getCount() / fristMetBean.getPage().getPageSize() +
                        (fristMetBean.getPage().getCount() % fristMetBean.getPage().getPageSize() == 0 ? 0 : 1);
                //Log.i(TAG, "setFristMetList: -----page------"+page+"--i---"+i);
                //Log.i(TAG, "setFristMetList: -----getList------"+fristMetBean.getPage().getList());
                if (page > i) {//判断是否是最后一页
                    linearLayout.setVisibility(View.VISIBLE);
                    radarView.stop();
                    radarView.setVisibility(View.GONE);
                    recycleviewFirstmet.setVisibility(View.GONE);
                } else {
                    if (page == 1) {
                        //list.clear();
                        //smartRefresh.finishRefresh();
                    }
                    if (fristMetBean.getPage().getList() != null) {
                        linearLayout.setVisibility(View.GONE);
                        radarView.stop();
                        radarView.setVisibility(View.GONE);
                        recycleviewFirstmet.setVisibility(View.VISIBLE);
                        list.addAll(fristMetBean.getPage().getList());
                        moCardAdapter.notifyDataSetChanged();
                    } else {
                        linearLayout.setVisibility(View.VISIBLE);
                        radarView.stop();
                        radarView.setVisibility(View.GONE);
                        recycleviewFirstmet.setVisibility(View.GONE);
                    }
                }
                SPUtils.setEditorKeyValue("longitude", String.valueOf(fristMetBean.getMap().getLongitude()));
                SPUtils.setEditorKeyValue("dimension", String.valueOf(fristMetBean.getMap().getDimension()));
                SPUtils.setEditorKeyValue("dimensionUpper", String.valueOf(fristMetBean.getMap().getDimensionLower()));
                SPUtils.setEditorKeyValue("longitudeUpper", String.valueOf(fristMetBean.getMap().getLongitudeUpper()));
                setThread();
            } else if (fristMetBean.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETURN_NO_TOKEN) {
                Utils.setToken(context);
            } else {
                linearLayout.setVisibility(View.VISIBLE);
                radarView.stop();
                radarView.setVisibility(View.GONE);
                recycleviewFirstmet.setVisibility(View.GONE);
                toast_MakeText(fristMetBean.getMsg());
            }
        }, throwable -> {
            toast_MakeText(getResources().getString(R.string.net_error));
            linearLayout.setVisibility(View.VISIBLE);
            radarView.stop();
            radarView.setVisibility(View.GONE);
            recycleviewFirstmet.setVisibility(View.GONE);
            Log.i(TAG, "setFristMetList: --throwable---" + throwable.toString());
        });
        defaultImageView.setEnabled(true);
    }

    /**
     * @return
     * @method
     * @description 播放语音
     * @date: 2018/9/28 18:57
     * @author: ljp
     */
    private void player(String audioFilePath, View view) throws FileNotFoundException {
        Log.i("player", "player: ---------" + audioFilePath);
        // Log.i(TAG, "player: ---voicePath--"+voicePath);
        // Log.i(TAG, "player: ---audioFilePath--"+audioFilePath);
        ImageView imageView = (ImageView) view;
        if (TextUtils.isEmpty(audioFilePath)) {
            return;
        }
        if (mediaUtil == null) {
            mediaUtil = MediaUtil.getInstance();
            mediaUtil.play(new FileInputStream(audioFilePath));
            imageView.setImageResource(R.mipmap.pause);
        } else {
            if (mediaUtil.setPlayer()) {
                mediaUtil.stop();
                imageView.setImageResource(R.mipmap.firstmet_open);
            } else {
                mediaUtil.play(new FileInputStream(audioFilePath));
                imageView.setImageResource(R.mipmap.pause);
            }
        }
        mediaUtil.setEventListener(new MediaUtil.EventListener() {
            @Override
            public void onStop() {
                imageView.setImageResource(R.mipmap.firstmet_open);
            }
        });
    }

    /**
     * @return
     * @method
     * @description 启动线程池下载语音介绍信息
     * @date: 2018/10/16 14:30
     * @author: ljp
     */
    private void setThread() {
        ThreadManager.getThreadPool().execute(runnable = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < list.size(); i++) {
                    String voiceInfo = list.get(i).getVoiceInfo();
                    int finalI = i;
                    OssClient.getInstance().init(context).fileDownload(voiceInfo, new OssClient.OnDownloadFile() {
                        @Override
                        public void onDownFileSuccess(InputStream inputStream) {
                            String voiceName = Utils.getVoiceName(list.get(finalI).getVoiceInfo());
                            //Log.i(TAG, "onDownFileSuccess: ---------"+voiceName);
                            String path = ConstantSet.VOICEINTR;
                            try {
                                OssConfig.writeToLocal(path, inputStream, voiceName);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void onDownFileProgress(String progress) {
                            //Log.i(TAG, "onDownFileProgress: ----------"+progress);
                        }
                    });
                }
            }
        });
    }

    /**
     * @return
     * @method
     * @description 喜欢请求
     * @date: 2018/10/22 16:09
     * @author: ljp
     */
    private void setLike(int position, int flag, FristMetBean.PageBean.ListBean listBean) {
        Log.i(TAG, "setLike: -----------flag--------------------" + flag);
        if (mySeleInfo.getvType().equals("0")) {
            if (count > 19) {
                list.remove(position);
                list.add(listBean);
                moCardAdapter.notifyDataSetChanged();
                showPopuVip();
            } else {
                FristMetService.fristMetLikeRight(token, deviceInfo, userId, listBean.getUserId()).subscribe(result -> {
                    Log.i(TAG, "setLike: -----不是会员-----" + result.toString());
                    if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETRUN_SUCCESS) {
                        if (flag == 1) {
                            list.remove(position);
                            moCardAdapter.notifyDataSetChanged();
                        } else {
                            callback.toRight(recycleviewFirstmet);
                        }
                        count++;
                    } else if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETURN_NO_TOKEN) {
                        Utils.setToken(context);
                    } else {
                        toast_MakeText(result.getMsg());
                    }
                }, throwable -> {
                    Log.i(TAG, "setLike: ----" + throwable.toString());
                });
            }
        } else {
            FristMetService.fristMetLikeRight(token, deviceInfo, userId, listBean.getUserId()).subscribe(result -> {
                Log.i(TAG, "setLike: -----是会员-----" + result.toString());
                if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETRUN_SUCCESS) {
                    if (flag == 1) {
                        list.remove(position);
                    } else {
                        callback.toRight(recycleviewFirstmet);
                    }
                    moCardAdapter.notifyDataSetChanged();
                } else if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETURN_NO_TOKEN) {
                    Utils.setToken(context);
                } else {
                    toast_MakeText(result.getMsg());
                }
            }, throwable -> {
                Log.i(TAG, "setLike: ----" + throwable.toString());
            });
        }
    }

    /**
     * @return
     * @method
     * @description 不喜欢请求
     * @date: 2018/10/22 16:09
     * @author: ljp
     */
    private void setUnLike(int position, int flag, FristMetBean.PageBean.ListBean listBean) {
        // Log.i(TAG, "setUnLike: ----" + count);
        if (mySeleInfo.getvType().equals("0")) {
            if (count > 20) {
                list.remove(position);
                list.add(listBean);
                moCardAdapter.notifyDataSetChanged();
                showPopuVip();
            } else {
                FristMetService.fristMetLikeLeft(token, deviceInfo, userId, listBean.getUserId()).subscribe(result -> {
                   // Log.i(TAG, "setLike: ----------" + result.getObject().toString());
                    if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETRUN_SUCCESS) {
                        if (flag == 1) {
                            list.remove(position);
                            moCardAdapter.notifyDataSetChanged();
                        } else {
                            callback.toLeft(recycleviewFirstmet);
                        }
                        count++;
                    } else if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETURN_NO_TOKEN) {
                        Utils.setToken(context);
                    } else {
                        toast_MakeText(result.getMsg());
                    }
                }, throwable -> {
                    Log.i(TAG, "setUnLike: ----" + throwable.toString());
                });
            }
            //moCardAdapter.notifyDataSetChanged();
        } else {
            FristMetService.fristMetLikeLeft(token, deviceInfo, userId, listBean.getUserId()).subscribe(result -> {
                Log.i(TAG, "setLike: ----------" + result.getObject().toString());
                if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETRUN_SUCCESS) {
                    if (flag == 1) {
                        list.remove(position);
                        moCardAdapter.notifyDataSetChanged();
                    } else {
                        callback.toLeft(recycleviewFirstmet);
                    }
                    count++;
                } else if (result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETURN_NO_TOKEN) {
                    Utils.setToken(context);
                } else {
                    toast_MakeText(result.getMsg());
                }
            }, throwable -> {
                Log.i(TAG, "setUnLike: ----" + throwable.toString());
            });
        }
    }

    /**
     * @return
     * @method
     * @description 不是会员滑动20次后，购买会员
     * @date: 2018/11/14 15:02
     * @author: ljp
     */
    private void showPopuVip() {
        View view = View.inflate(context, R.layout.popu_frist_met_vip, null);
        PopUtils.showPopupWindow(activity, view, true);
        initPopuView(view);
    }

    RelativeLayout relaVip1;
    RelativeLayout relaVip12;
    RelativeLayout relaVip3;
    TextView tv3Month;
    TextView tv18Money;
    TextView tvMoney3;
    TextView tv12Month;
    TextView tvMoney168;
    TextView tv50Money;
    TextView tv1Month;
    TextView tvMoney;
    TextView tv168Money;
    String money;
    int[] stringsBag = {R.mipmap.firstmet_vip_1, R.mipmap.firstmet_vip_2,
            R.mipmap.firstmet_vip_3, R.mipmap.firstmet_vip_4, R.mipmap.firstmet_vip_5};
    int[] stringsIcon = {R.mipmap.firstmet_vip_icon_1, R.mipmap.firstmet_vip_icon_2,
            R.mipmap.firstmet_vip_icon_3, R.mipmap.firstmet_vip_icon_4, R.mipmap.firstmet_vip_icon_5};

    List<VipCustomBean> vipCustomBeans = new ArrayList<>();

    /**
     * @return
     * @method
     * @description 购买会员布局实例化
     * @date: 2018/11/14 15:06
     * @author: ljp
     */
    private void initPopuView(View view) {
        BannerLayout bannerLayout = view.findViewById(R.id.banner_layout);//banner
        ImageView close = view.findViewById(R.id.image_close);
        relaVip1 = view.findViewById(R.id.rela_vip_1);//1个月会员
        relaVip3 = view.findViewById(R.id.rela_vip_3);//3个月会员
        relaVip12 = view.findViewById(R.id.rela_vip_12);//12个月会员
        CheckBox radioButton = view.findViewById(R.id.radio_vip_renew);//默认选中
        RelativeLayout radioGroup = view.findViewById(R.id.radio_group);//默认选中

        TextView tvBuy = view.findViewById(R.id.tv_buy);//购买会员
        TextView tv3MonthOriginalCost = view.findViewById(R.id.tv_3_month_original_cost);
        TextView tv12MonthOriginalCost = view.findViewById(R.id.tv_12_month_original_cost);
        tv3Month = view.findViewById(R.id.tv_3_month);
        tvMoney3 = view.findViewById(R.id.tv_money_3);
        tv18Money = view.findViewById(R.id.tv_18_money);
        tv12Month = view.findViewById(R.id.tv_12_month);
        tvMoney168 = view.findViewById(R.id.tv_money_168);
        tv50Money = view.findViewById(R.id.tv_50_money);
        tv1Month = view.findViewById(R.id.tv_1_month);
        tvMoney = view.findViewById(R.id.tv_money);
        tv168Money = view.findViewById(R.id.tv_168_money);
       /* //画线效果
        tv3MonthOriginalCost.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tv12MonthOriginalCost.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);*/
        //banner
        FristVIPBannerAdapter fristVIPBannerAdapter = new FristVIPBannerAdapter(context, vipCustomBeans);
        bannerLayout.setAdapter(fristVIPBannerAdapter);
        bannerLayout.setCenterScale(1.0f);
        bannerLayout.setShowIndicator(true);
        bannerLayout.setAutoPlaying(false);
        bannerLayout.setMoveSpeed(0.8f);
        relaVip1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setLayoutCacalBg(relaVip1, tv1Month, tvMoney, tv18Money);
            }
        });
        relaVip3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setLayoutCacalBg(relaVip3, tv3Month, tvMoney3, tv50Money);
            }
        });
        relaVip12.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setLayoutCacalBg(relaVip12, tv12Month, tvMoney168, tv168Money);
            }
        });
        tvBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, BuyVIPActivity.class);
                intent.putExtra("data","");
                startActivity(intent);
               /* Uri uri = Uri.parse("https://www.chujian.live/faint-service/static/h5/app/memberh5.html?id=" + mySeleInfo.getNumber());
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);*/
            }
        });
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PopUtils.hidePopupWindow();
            }
        });
        radioGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (radioButton.isChecked()) {
                    radioButton.setChecked(false);
                } else {
                    radioButton.setChecked(true);
                }
            }
        });
    }

    /**
     * @return
     * @method
     * @description 改变选定布局背景和字体颜色
     * @date: 2018/10/9 19:57
     * @author: ljp
     */
    private void setLayoutBg(RelativeLayout rela, TextView tvMonth, TextView tvmoney, TextView tvmoneySum) {
        rela.setSelected(true);
        tvMonth.setTextColor(getResources().getColor(R.color.colorC9A874));
        tvmoney.setTextColor(getResources().getColor(R.color.color9C7C4A));
        tvmoneySum.setTextColor(getResources().getColor(R.color.color9C7C4A));
        money = tvmoneySum.getText().toString();
    }

    /**
     * @return
     * @method
     * @description 改变未选定布局背景和字体颜色
     * @date: 2018/10/9 19:57
     * @author: ljp
     */
    private void setLayoutUnseBg(RelativeLayout rela, TextView tvMonth, TextView tvmoney, TextView tvmoneySum) {
        rela.setSelected(false);
        tvMonth.setTextColor(getResources().getColor(R.color.color666666));
        tvmoney.setTextColor(getResources().getColor(R.color.colorC9A874));
        tvmoneySum.setTextColor(getResources().getColor(R.color.colorC9A874));
    }

    private void setLayoutCacalBg(RelativeLayout rela, TextView tvMonth, TextView tvmoney, TextView tvmoneySum) {
        if (rela == relaVip1) {
            setLayoutUnseBg(relaVip3, tv3Month, tvMoney3, tv50Money);
            setLayoutUnseBg(relaVip12, tv12Month, tvMoney168, tv168Money);
            setLayoutBg(rela, tvMonth, tvmoney, tvmoneySum);
        } else if (rela == relaVip3) {
            setLayoutUnseBg(relaVip1, tv1Month, tvMoney, tv18Money);
            setLayoutUnseBg(relaVip12, tv12Month, tvMoney168, tv168Money);
            setLayoutBg(rela, tvMonth, tvmoney, tvmoneySum);
        } else if (rela == relaVip12) {
            setLayoutUnseBg(relaVip1, tv1Month, tvMoney, tv18Money);
            setLayoutUnseBg(relaVip3, tv3Month, tvMoney3, tv50Money);
            setLayoutBg(rela, tvMonth, tvmoney, tvmoneySum);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ThreadManager.getThreadPool().cancel(runnable);
        if (mediaUtil != null) {
            mediaUtil.stop();
        }
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (hidden) {//此时fragment切换了，停止播放
            ThreadManager.getThreadPool().cancel(runnable);
            if (mediaUtil != null) {
                mediaUtil.stop();
            }
        } else {
            //player(voiceName);
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        ThreadManager.getThreadPool().cancel(runnable);
        if (mediaUtil != null) {
            mediaUtil.stop();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}

